package me.ereach.internalback.controller;

import me.ereach.internalback.mapper.VXHSysUserMapper;
import me.ereach.internalback.viewmodel.VXHSysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/sys")
public class CtrlVXHUsers {
    @Autowired
    private VXHSysUserMapper vxhSysUserMapper;

    @PostMapping("/user/close")
    public VXHSysUser userClose(
            @RequestParam("username") String username
    ) {
        VXHSysUser vxhSysUser = vxhSysUserMapper.closeVXHSysUser(username);
        return vxhSysUser;
    }

    @PostMapping("/user/open")
    public VXHSysUser userOpen(
            @RequestParam("username") String username
    ) {
        VXHSysUser vxhSysUser = vxhSysUserMapper.openVXHSysUser(username);
        return vxhSysUser;
    }

    @PostMapping("/user/login")
    public VXHSysUser userLogin(
            @RequestParam("username") String username,
            @RequestParam("password") String password
    ) {
        VXHSysUser vxhSysUser = vxhSysUserMapper.loginVXHSysUser(username, password);
        return vxhSysUser;
    }

    @PostMapping("/user")
    public VXHSysUser insertUser(
            @RequestParam("username") String username,
            @RequestParam("password") String password,
            @RequestParam("acttype") Byte acttype
    ) {
        VXHSysUser vxhSysUser = vxhSysUserMapper.insertVXHSysUser(username, password, acttype);
        return vxhSysUser;
    }

    @GetMapping("/user")
    public List<VXHSysUser> getVXHSysUser() {
        List<VXHSysUser> vxhSysUsers = vxhSysUserMapper.selectList(null);
        return vxhSysUsers;
    }
}
